#!/bin/bash

# 执行结果判断函数
function log() {
    if [ $? -eq 0 ]; then
        echo -e "$(date -d "+8 hours"): \e[32m$1==========>succeed\e[0m" >> /var/log/mf-backup.log
    else
        echo -e "$(date -d "+8 hours"): \e[31m$1==========>failed\e[0m" >> /var/log/mf-backup.log
        exit 1
    fi
}


#web_publish
rbd snap create rbd/8794e2e8-ecd3-4815-9cdd-8b5900cef661@"$(date +%Y%m%d)-bak" >/dev/null 2>&1
log "Snap web_publish rbd/8794e2e8-ecd3-4815-9cdd-8b5900cef661@$(date +%Y%m%d)-bak"
# sleep 3s

#app
rbd snap create rbd/a7ee0c30-46d3-4f82-bf53-031d4b3126b3@"$(date +%Y%m%d)-bak" >/dev/null 2>&1
log "Snap app rbd/a7ee0c30-46d3-4f82-bf53-031d4b3126b3@$(date +%Y%m%d)-bak"
# sleep 60s

#data
rbd snap create rbd/89c6d218-34e4-4863-b70e-3cbf614a4c4e@"$(date +%Y%m%d)-bak" >/dev/null 2>&1
log "Snap data rbd/89c6d218-34e4-4863-b70e-3cbf614a4c4e@$(date +%Y%m%d)-bak"

sleep 10s
# 前一天日期
# echo $(date -d "$(date +%Y%m%d) -1 day" +%Y%m%d)

# 备份
# web_publish
qemu-img convert -p -O qcow2 rbd:rbd/8794e2e8-ecd3-4815-9cdd-8b5900cef661@"$(date +%Y%m%d)"-bak  /data/backup/backup/system_bak/web_publish/web_publish_"$(date +%Y%m%d)".qcow2 >/dev/null 2>&1
log "Backup web_publish rbd/8794e2e8-ecd3-4815-9cdd-8b5900cef661@$(date +%Y%m%d)-bak"
# sleep 60s

# app
qemu-img convert -p -O qcow2 rbd:rbd/a7ee0c30-46d3-4f82-bf53-031d4b3126b3@"$(date +%Y%m%d)"-bak /data/backup/backup/system_bak/app/App_"$(date +%Y%m%d)".qcow2 >/dev/null 2>&1
log "Backup app rbd/a7ee0c30-46d3-4f82-bf53-031d4b3126b3@$(date +%Y%m%d)-bak"
# sleep 60s

# data
qemu-img convert -p -O qcow2 rbd:rbd//89c6d218-34e4-4863-b70e-3cbf614a4c4e@"$(date +%Y%m%d)"-bak /data/backup/backup/system_bak/data/data_"$(date +%Y%m%d)".qcow2  >/dev/null 2>&1
log "Backup data rbd//89c6d218-34e4-4863-b70e-3cbf614a4c4e@$(date +%Y%m%d)-bak"


sleep 10s
# 删除
# web_publish
rbd snap rm rbd/8794e2e8-ecd3-4815-9cdd-8b5900cef661@"$(date +%Y%m%d)"-bak >/dev/null 2>&1
log "Drop-snap web_publish rbd/8794e2e8-ecd3-4815-9cdd-8b5900cef661@$(date +%Y%m%d)-bak"
# sleep 60s

# app
rbd snap rm rbd/a7ee0c30-46d3-4f82-bf53-031d4b3126b3@"$(date +%Y%m%d)"-bak >/dev/null 2>&1
log "Drop-snap app rbd/a7ee0c30-46d3-4f82-bf53-031d4b3126b3@$(date +%Y%m%d)-bak"
# sleep 60s

# data
rbd snap rm rbd/89c6d218-34e4-4863-b70e-3cbf614a4c4e@"$(date +%Y%m%d)-bak" >/dev/null 2>&1
log "Drop-snap data rbd/89c6d218-34e4-4863-b70e-3cbf614a4c4e@$(date +%Y%m%d)-bak"





